package org.platform.processor.diagnose.impl;

import lombok.extern.slf4j.Slf4j;
import org.platform.mo.db.FdDiagnosetask;
import org.platform.processor.diagnose.DiagnoseTaskProcessor;
import org.platform.processor.diagnose.IDiagnoseExecutor;
import org.platform.tool.helper.LogHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * 测试任务诊断
 *
 * @author
 */
@Service
@Slf4j
public class TestFaultDiagnoseImpl implements IDiagnoseExecutor {
    @Autowired
    private DiagnoseTaskProcessor processor;
    @Autowired
    private LogHelper logHelper;

    @Override
    public boolean doExecute(FdDiagnosetask task) {
        try {
            processor.testPlan(task);
            String content = "测试诊断任务文件下发【成功】";
            logHelper.normal(content, task.getDiagnoseid(), task.getDeviceid());
            return true;
        } catch (IOException e) {
            String content = "测试诊断任务文件下发【失败】";
            logHelper.error(content, task.getDiagnoseid(), task.getDeviceid(), e);
        }
        return false;
    }
}

